package com.example.administrator.zhongyichou.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.zhongyichou.help.ImageLoader;
import com.example.administrator.zhongyichou.help.StringImageToList;
import com.example.administrator.zhongyichou.net.protocol.MyProjectProtocol;
import com.example.administrator.zhongyichou.help.DateUtils;
import com.example.administrator.zhongyichou.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by lichenyu on 2017/11/24.
 * 描述：
 */

public class MyLaunchListAdapter extends ListBaseAdapter {
    public MyLaunchListAdapter(Context mContext, List list) {
        super(mContext, list);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.my_launch_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        MyProjectProtocol.DataBean bean = (MyProjectProtocol.DataBean) getData(position);
        holder.txtTitle.setText(bean.getInfo_title());
        holder.txtTime.setText("发布于" + DateUtils.stampToDate(bean.getCreate_time()));
        switch (bean.getAudit_status()) {
            case "0":
                holder.txtType.setText("待审核");
                break;
            case "1":
                holder.txtType.setText("审核中");
                break;
            case "2":
                holder.txtType.setText("审核未通过");
                break;
            case "3":
                holder.txtType.setText("已拒绝");
                break;
            case "4":
                holder.txtType.setText("筹款中");
                break;
            case "5":
                holder.txtType.setText("已结束");
                break;
        }
        ImageLoader.centerCropUrl(getContext(), StringImageToList.toImage(bean.getInfo_img()), holder.imgHead);
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.img_head)
        ImageView imgHead;
        @BindView(R.id.txt_title)
        TextView txtTitle;
        @BindView(R.id.txt_time)
        TextView txtTime;
        @BindView(R.id.txt_type)
        TextView txtType;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
